#encoding=utf8
"""
Django settings for website project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'b%(4*9*f!1(&!d3)!a$@j!29g6!^v%wq(zvxmz(srp+lb(8)!d'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG =False

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = [ '*' ]


# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'trp',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
#     'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    #'django.middleware.transaction.TransactionMiddleware',
)

# add tmp
MIDDLEWARE_CLASSES +=(
                      'utils.printSql.PrintSQL',
)
TEMPLATE_CONTEXT_PROCESSORS = (
#         "django.contrib.auth.context_processors.csrf",
        "django.contrib.auth.context_processors.auth",
        "django.core.context_processors.request",
)
ROOT_URLCONF = 'website.urls'

WSGI_APPLICATION = 'website.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'trp_gometest',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'd189.mzhen.cn',
        'PORT': '3306',
        'OPTIONS': {
            'init_command': 'SET storage_engine=INNODB',
        }
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_L10N = True

USE_TZ = False


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
    os.path.join(BASE_DIR, "trp/static"),
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

TEMPLATE_DIRS = (
    os.path.join(BASE_DIR, 'trp/templates'),
    os.path.join(BASE_DIR, 'templates'),
)

from utils.utils import create_file_not_exists

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'console':{
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose'
        },
        'file':{
            'level': 'DEBUG',
            'class': 'logging.handlers.TimedRotatingFileHandler',
            'formatter': 'verbose',
            'when':'d',
            'filename':create_file_not_exists('logs/trp.log')
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'INFO',
            'propagate': True,
        },
        'trp_logger':{
            'handlers':['console','file'],
            'level':'DEBUG',
            'propagate': True,
        }
    },
    'formatters':{
        'verbose':{
            'format': '[%(asctime)s]  [%(levelname)s]  [module=%(filename)s,function=%(funcName)s,lineno=%(lineno)d]  %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        }
    }
}
# global logger
import logging
LOGGER = logging.getLogger("trp_logger")

LOGIN_URL = '/trp/login/'
BUSINESS = {
    'host': 'd189.mzhen.cn',
    'port': 7000,
    'url': '/report/get/',
}

MATERIAL={
    "host":"d189.mzhen.cn",#物料服务器地址
    "port":80,#物料服务器端口
    "timeout":200,#连接超时时间
    "upload_url":"/material/upload/",#物料服务器上传url
    "review_url":"/material/review/",#物料服务器查看物料url，暂时系统没用到
    "delete_url":"/material/delete/",#物料删除url，暂时系统没用到
    "tmp_dir":"/tmp/",#website 临时存储img目录 
    "img_format":["JPG","GIF","PNG","BMP"],#支持上传的图片格式，格式大写
    "flash_format":["SWF"]#支持flash上传的格式,格式大写
}

ADSERVING_URL='http://d189.mzhen.cn/static/adserving/'
STATIC_ROOT='/home/workspace/nginx/static/'
